<template>
  <div class="wrap">
    <div class="head cd">
      <img src="../assets/loginLogo.png" class="logo" alt />
      <div class="nav">
        <router-link class="tab" to="/addOrder">
          <img src="../assets/nav1.png" alt />
          <img src="../assets/nav1act.png" alt />
          <p>添加订单</p>
        </router-link>
        <router-link  class="tab" to="/order" @mouseover="hover" @mouseleave="state = false">
          <img src="../assets/nav2.png"  style="width:28px" alt />
          <img src="../assets/nav2act.png"  style="width:28px;" alt />
          <p>订单管理</p>
          <!-- <div class="draw" v-if="state">
            <router-link class="p" tag="p" to="/order">我的订单</router-link>
            <router-link class="p" tag="p" to="/send">代发订单</router-link>
          </div> -->
        </router-link >
        <router-link class="tab" to="/callList">
          <img src="../assets/nav3.png" alt />
          <img src="../assets/nav3act.png" alt />
          <p>通讯录</p>
        </router-link>
        <router-link class="tab" to="/person">
          <img src="../assets/nav4.png" alt />
          <img src="../assets/nav4act.png" alt />
          <p>商家中心</p>
        </router-link>
        <router-link class="tab" to="/about">
          <img src="../assets/nav5.png" style="width:28px" alt />
          <img src="../assets/nav5act.png" style="width:28px" alt />
          <p>联系我们</p>
        </router-link>
      </div>
      <div class="user">
        <div v-if="userInfo">
          <p>{{userInfo.username}}</p>
          <img :src="userInfo.avatar" :onerror="defaultImg3" class="headeravi" alt />
        </div>
        <el-button type="primary" style="width:80px" @click="out" size="mini" round>退出</el-button>
      </div>
    </div>
    <div class="mead">
      <img src="../assets/loginLogo.png" class="logo" alt />
      <img src="../assets/llok.png" class="ct" @click="drawer=!drawer" alt />
    </div>
    <el-drawer
      :visible.sync="drawer"
      :direction="direction"
      :before-close="handleClose"
      :with-header="false"
      size
    >
      <div class="nav">
        <router-link class="tab" to="/addOrder">
          <p @click="drawer = false">添加订单</p>
        </router-link>
        <router-link class="tab" to="/order">
          <p @click="drawer = false">订单管理</p>
        </router-link>
        <router-link class="tab" to="/callList">
          <p @click="drawer = false">通讯录</p>
        </router-link>
        <router-link class="tab" to="/person">
          <p @click="drawer = false">商家中心</p>
        </router-link>
        <router-link class="tab" to="/about">
          <p @click="drawer = false">联系我们</p>
        </router-link>
        <!-- <el-button type="primary" style="width:80px;margin-left:30px" @click="out" size="mini" round>退出</el-button> -->
        <p @click="out">退出</p>
      </div>
      <!-- <div class="user">
        <div v-if="userInfo">
          <p>{{userInfo.username}}</p>
          <img :src="userInfo.avatar" :onerror="defaultImg3" class="headeravi" alt />
        </div>
        <el-button type="primary" style="width:80px" @click="out" size="mini" round>退出</el-button>
      </div>-->
    </el-drawer>
    <router-view></router-view>
  </div>
</template>
<style lang="scss" scoped>
.wrap {
  margin: 0 auto;
  max-width: 1400px;
}
.head {
  height: 60px;
  background: #fff;
  border-bottom: 1px solid rgba(229, 229, 229, 1);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .logo {
    width: 40px;
  }
  .nav {
    display: flex;
    align-items: center;
    height: 50px;
    max-width: 700px;
    justify-content: space-between;
    margin-top: 10px;
  }
  .tab {
    color: #333;
    text-decoration: none;
    display: block;
    height: 100%;
    width: 100px;
    img {
      width: 22px;
      height: 22px;
      display: block;
      margin: 0 auto;
    }
    img:nth-of-type(1) {
      display: block;
    }
    img:nth-of-type(2) {
      display: none;
    }
    p {
      font-size: 12px;
      margin-top: 6px;
      text-align: center;
      color: #999;
    }
    .draw {
      background: #dbdbdb;
      border-radius: 4px;
      margin-top: 6px;
      z-index: 999;
      position: absolute;
      width: 100px;

      .p {
        height: 30px;
        line-height: 30px;
        display: block;
        border: none;
        &:hover {
          background: #719bef;
          color: #fff;
        }
      }
    }
  }
  .router-link-active {
    border-bottom: 2px solid #719bef;
    img:nth-of-type(1) {
      display: none;
    }
    img:nth-of-type(2) {
      display: block;
    }
  }
}
.user {
  display: flex;
  align-items: center;
  div {
    display: flex;
    align-items: center;
    margin-right: 30px;
    p {
      color: #555;
      font-size: 16px;
      margin-right: 8px;
    }
    .headeravi {
      display: block;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      object-fit: cover;
    }
  }
}
.mead{
  display: none;
}
@media screen and (max-width: 1400px) {
.wrap{
    padding: 0 30px;
  }
}
@media screen and (max-width: 760px) {
  .wrap{
    padding: 0 30px;
  }
  .cd {
    display: none;
  }
  .mead {
    display: block;
    height: 60px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    border-bottom: 1px solid rgba(229, 229, 229, 1);
    .logo {
      width: 40px;
    }
    .ct {
      width: 40px;
    }
  }
  .tab {
    text-decoration: none;
    display: block;
  }
  p {
    font-size: 12px;
    margin-top: 6px;
    text-align: left;
    color: #999;
    margin-left: 30px;
    line-height: 40px;
    cursor: pointer;
  }
}
</style>
<script>
import { logOut, findUserInfo } from "../utils/interface";
export default {
  data() {
    return {
      userInfo: null,
      defaultImg3: 'this.src="' + require("../assets/person.png") + '"',
      state: false,
      drawer: false,
      direction: "ttb"
    };
  },
  methods: {
    // 退出登陆
    out() {
      logOut().then(res => {
        if (res.data.code == 200) {
          this.$confirm("是否退出当前账号", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
            .then(() => {
              this.$router.push("/");
              localStorage.removeItem("shopPC");
            })
            .catch(() => {});
        }
      });
    },
    hover() {
      this.state = true;
      console.log(this.state)
    },
    // 查询用户信息
    getuserInfo() {
      findUserInfo().then(res => {
        this.userInfo = res.data.data;
        localStorage.setItem("userInfo", JSON.stringify(res.data.data));
      });
    },
    handleClose(){}
  },
  mounted() {
    this.getuserInfo();
    this.bus.$on('users',(n)=>{
       this.getuserInfo();
    })
  }
};
</script>